package game.view.panel.game
{
	import com.base.type.LayerEnum;
	import com.greensock.TweenMax;
	import com.net.SocketManage;
	
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	
	import game.GlobalConfig;
	import game.controller.mediator.ResultPanelMediator;
	import game.model.GameData;
	import game.model.type.*;
	import game.util.*;
	import game.view.base.gamepanel.ResultPanelUI;
	
	import morn.App;
	import morn.core.components.Box;
	import morn.core.components.Component;
	import morn.core.components.Image;
	import morn.core.components.Label;
	import morn.core.events.UIEvent;
	import morn.core.handlers.Handler;
	import morn.core.managers.ResLoader;
	public class ResultPanel extends ResultPanelUI
	{
		private var a_nameList:Array=['30','60','150','300','666','1500'];
		private var xyList:Array=[];
		private var goodsViewList:Array=[];
		public function ResultPanel()
		{
			super();
			setLayerType(LayerEnum.LAYER_SINGLE);
			setMediatorClass(ResultPanelMediator);
		}
		override protected function initialize():void
		{
			super.initialize();
			endBtn.setLabel('结束挑战','收下奖励');
			nextBtn.setLabel('挑战下一关','放弃本关奖励');
			autoBtn.setLabel('停止跳跃','退出自动状态');
			autoBtn.addEventListener(MouseEvent.CLICK,autoBtnClick);
			endBtn.addEventListener(MouseEvent.CLICK,closeBtnClick);
			nextBtn.addEventListener(MouseEvent.CLICK,nextBtnClick);
			endBtn.visible=nextBtn.visible=autoBtn.visible=false;
			trace('ResultPanel initialize');
		}
		override protected function reset():void
		{
			super.reset();
			trace('ResultPanel reset===================',GameData.instance.automaticIndex,GameData.instance.myLevelId,GameData.instance.proLeId);
			var isauto:Boolean=false;
			
			if(GameData.instance.automaticIndex!=Enum.no_num){
				if(GameData.instance.automaticIndex>=GameData.instance.myLevelId){
					isauto=true;
				}
				if(GameData.instance.proLeId==6){
					isauto=false
				}
			}
			if(isauto){
				autoBtn.visible=true;
				App.timer.doOnce(1000,this.timeHandler);
			}else{
				endBtn.visible=nextBtn.visible=true;
			}
			if(GameData.instance.proLeId==6){
				nextBtn.visible=false;endBtn.x=414;
			}else{
				endBtn.x=302;nextBtn.x=536;
			}
			//goodsImg.url='png.img.goods.'+GameData.instance.resultData.awardId;
			gsbgimg.url='png.img.game.blockBg'+GameData.instance.resultData.awardId;
			moneyLabel.text='价值'+GameData.instance.resultData.awardMoney+'呱元';
			nameLabel.text=GameData.instance.resultData.awardName+'*'+GameData.instance.resultData.amount;
			/*App.loader.load(GameData.instance.resultData.awardImg,1,new Handler(function(bit:BitmapData):void{
				goodsImg.bitmapData=bit;	
			}));*/
			amountimg.url='png.img.game.'+a_nameList[GameData.instance.resultData.awardId-1];
			switch(GameData.instance.resultData.awardId){
				case 1:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=51;amountimg.x=44;amountimg.y=151;amountimg.scale=1;
					break;
				case 2:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=51;amountimg.x=44;amountimg.y=151;amountimg.scale=1;
					break;
				case 3:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=51;amountimg.x=44;amountimg.y=151;amountimg.scale=1;
					break;
				case 4:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=51;amountimg.x=44;amountimg.y=151;amountimg.scale=1;
					break;
				case 5:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=9;amountimg.x=44;amountimg.y=151;amountimg.scale=1;
					break;
				case 6:
					goodsImg.x=48;goodsImg.y=64;gsbgimg.x=0;gsbgimg.y=-29;amountimg.x=37;amountimg.y=151;amountimg.scale=0.6;
					break;
			}
		}
		override protected function updateData(data:Object):void
		{
			
		}
		private function timeHandler():void{
			trace('ResultPanel timeHandler');
			//var vo:Object={"cmd": "Jump", "params": {}};
			//SocketManage.instance.sendUTF(JSON.stringify(vo));
			//this.closeView();
			this.nextBtnClick(null);
		}
		private function setData(data:Object):void{
		}
		private function nextBtnClick(e:MouseEvent):void{
			var vo:Object={"cmd": "Choose", "params": {'type':2}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			GameData.instance.isJxToJ=true;
			this.closeView();
		}
		private function closeBtnClick(e:MouseEvent):void{
			var vo:Object={"cmd": "Choose", "params": {'type':1}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			this.closeView();
		}
		private function autoBtnClick(e:MouseEvent):void{
			var vo:Object={"cmd": "Choose", "params": {'type':1}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			this.closeView();
		}
		private function closeView():void{
			App.timer.clearTimer(this.timeHandler);
			ZooMain.view.closeView(ResultPanel);
		}
		override protected function dispose():void{
			autoBtn.removeEventListener(MouseEvent.CLICK,closeBtnClick);
			endBtn.removeEventListener(MouseEvent.CLICK,closeBtnClick);
			nextBtn.removeEventListener(MouseEvent.CLICK,nextBtnClick);
			super.dispose();
		}
	}
}